package jacker.bit.price;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


public class UtilAndroid implements Serializable{
	
	private static final long serialVersionUID = -2212472666227063861L;
	
	public final static DateFormat YMD = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	
	
	public static boolean hasInternet(Context ctx,boolean showinfo){
		
		ConnectivityManager manager = 
			(ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

		NetworkInfo info = manager.getActiveNetworkInfo();

		boolean result = false;
		
		if (info != null) 
			result = info.isConnected();
		
		if(!result && showinfo){
			showToastMsg(ctx.getText(R.string.no_connection_alert),ctx);
		}
		
		return result;

	}
	
	
	
	public static void showToastMsg(CharSequence msg,Context ctx){
		Intent intent = new Intent(ctx,ReceiverMsg.class);
		//Intent intent = new Intent(ctx,SendResultReceiver.class);
		intent.putExtra("msg", msg );
		ctx.sendBroadcast(intent);
	}
	


}
